import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  UseGuards
} from '@nestjs/common';
import { RolesService } from '@/modules/roles/roles.service';
import { CreateRoleDto } from '@/modules/roles/create-role.dto';
import { UpdateRoleDto } from '@/modules/roles/update-role.dto';
import { Roles } from '@/decorators/role.decorator';
import { Role } from '@/enum/role.enum'

@Controller('roles')
@Roles(Role.Admin)
export class RolesController {
  constructor(private readonly rolesService: RolesService) {}

  @Get(':id')
  getRole(@Param('id') id: number) {
    return this.rolesService.findOne(id);
  }

  @Get()
  getRoles() {
    return this.rolesService.findAll();
  }

  @Post()
  addRole(@Body() createRoleDto: CreateRoleDto) {
    return this.rolesService.create(createRoleDto);
  }

  @Delete(':id')
  delRole(@Param('id') id: number) {
    return this.rolesService.remove(id);
  }

  @Put()
  updateRole(@Body() updateRoleDto: UpdateRoleDto) {
    return this.rolesService.update(Number(updateRoleDto.id), updateRoleDto);
  }
}
